package com.whl.mybatis.builder;

import org.apache.ibatis.mapping.*;
import org.apache.ibatis.session.Configuration;

import java.util.ArrayList;
import java.util.List;

public class MybatisBuilder {

	public static List<ResultMap> resultMap(Configuration configuration, String id, Class<?> type,
			List<ResultMapping> resultMappings) {
		List<ResultMap> resultMaps = new ArrayList<ResultMap>();
		if (resultMappings == null) {
			resultMappings = new ArrayList<ResultMapping>();
		}
		ResultMap resultMap = new ResultMap.Builder(configuration, id, Integer.class, resultMappings).build();
		resultMaps.add(resultMap);
		return resultMaps;
	}

	public static MappedStatement mappedStatement(Configuration configuration, String id, SqlSource sqlSource,
			SqlCommandType sqlCommandType, ParameterMap parameterMap, List<ResultMap> resultMaps) {
		MappedStatement mappedStatement = new MappedStatement.Builder(configuration, id, sqlSource, sqlCommandType)
				.parameterMap(parameterMap).resultMaps(resultMaps).build();
		return mappedStatement;
	}

}
